package com.ls.bpmn.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ls.bpmn.entity.Category;
import com.ls.bpmn.mapper.CategoryMapper;
import com.ls.bpmn.service.ICategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ls
 * @since 2025-04-21
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> getAllCategories() {
        return categoryMapper.selectList(null);  // 查询所有分类
    }


    @Override
    public boolean saveCategory(Category category) {
        return categoryMapper.insert(category) > 0;
    }

    @Override
    public boolean updateCategory(Category category) {
        return categoryMapper.updateById(category) >0;
    }

    @Override
    public boolean deleteCategory(String id) {
        return categoryMapper.deleteById(id) > 0;
    }

    public List<Category> getCategoriesByParentId(String parentId) {
        return categoryMapper.selectList(
                new QueryWrapper<Category>().eq("parent_id", parentId)
        );
    }
}
